package com.xsherl.leetcode.solution;

import com.xsherl.leetcode.utils.PrintUtils;

public class MergeSortedArray {

    public void merge(int[] nums1, int m, int[] nums2, int n) {
        int len = m + n;
        m--;
        n--;
        for (int i = len - 1; i >= 0 && m >= 0 && n >= 0; --i){
            if (nums2[n] > nums1[m]){
                nums1[i] = nums2[n];
                n--;
            } else {
                nums1[i] = nums1[m];
                m--;
            }
        }
        while (n >= 0){
            nums1[n] = nums2[n];
            n--;
        }
    }

    public static void main(String[] args) {
        int[] nums1 = {0,0,0,0};
        int m = 0;
        int[] nums2 = {1};
        int n = 1;
        PrintUtils.println(nums1);
        new MergeSortedArray().merge(nums1, m, nums2, n);
        PrintUtils.println(nums1);
    }

}
